<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<!--admin page-->
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="Content-Language" content="zh-CN">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>Url shorten app</title>

<!--    import jquery, bootstrap and datatable source by cdn-->
    <script th:src="@{https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js}"></script>
    <link href="https://cdn.bootcss.com/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" type="text/css">
    <script src="https://cdn.bootcss.com/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <link rel="stylesheet" type="text/css" href="http://cdn.datatables.net/1.10.15/css/jquery.dataTables.css">``
    <script type="text/javascript" charset="utf8" src="http://cdn.datatables.net/1.10.15/js/jquery.dataTables.js"></script>

    <style>
        @media (min-width: 1650px) {
            .container {
                width: 1200px;
            }
        }
    </style>
</head>
<body>

<div class="container">
    <br>
    <h1 style="font-size: x-large;" align="center">Urls statistic</h1><br>
    <br>
    <div class="row" th:if="${session.user}">
        <div class="col-xs-12 col-md-12" align="right">
            <a id="refresh" class="btn btn-primary" href="javascript:void(0);">Refresh</a> &nbsp;
            <a class="btn btn-info" href="/logout">Logout</a>
        </div>
    </div>
    <br>

    <div>
        <main>
            <div class="container-fluid px-4">
                <div class="card mb-4">
                    <div class="card-body">
                        <table id="url_table" class="table table-bordered no-footer dataTable">
                            <thead>
                            <tr>
                                <th>Username</th>
                                <th>Original Url</th>
                                <th>Shorten Url</th>
                                <th>Visits</th>
                                <th>Last visited time</th>
                            </tr>
                            </thead>
                            <tbody th:each="url:${allUrl}">
                            <tr>
                                <td th:text="${url.userName}"></td>
                                <td th:text="${url.originUrl}"></td>
                                <td th:text="${url.shortUrlId}"> </td>
                                <td th:text="${url.visits}"></td>
                                <td th:text="${url.lastVisited}"></td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </main>
    </div>

</div>

<script>

        $("#url_table").dataTable();

    //销毁datatable
    $("#cls_modal").click(function () {
        $("#url_table>tbody").empty();
        if ($('#url_table').hasClass('dataTable')) {
            let dttable = $('#url_table').dataTable();
            dttable.fnClearTable();
            dttable.fnDestroy();
        }
    })

</script>
</body>
</html>